export default function cspPlugin(env) {
    return {
        name: 'vite:csp',
        transformIndexHtml(html) {
          if (env.VITE_APP_ENV === 'production') {
            return {
              html,
              tags: [
                {
                  tag: 'meta',
                  attrs: {
                    'http-equiv': 'Content-Security-Policy',
                    // 这里根据实际项目需求修改配置,可以配置到env文件
                    content: `
                        default-src 'self';
                        script-src 'self' 'unsafe-inline' 'unsafe-eval';
                        style-src 'self' 'unsafe-inline';
                        img-src 'self' data: http: https:;
                        connect-src * ;
                        font-src 'self' http://at.alicdn.com;
                      `.replace(/\s+/g, ' ').trim()
                  },
                  injectTo: 'head-prepend'
                }
              ]
            }
          }
          return html
        }
      }
}
